
const tokens = {
  admin: {
    token: 'admin-token'
  },
  user: {
    token: 'user-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    permissions: [],
    userName: '系统管理员',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    userInfo: {
      userId: 1,
      userCode: 'admin',
      userAvatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      userName: '系统管理员',
      userPhone: '',
      userEmail: '',
      orgCode: '',
      orgName: '',
      counterCode: '',
      counterName: '',
      userType: '',
      token: 'admin-token',
      commonUserCode: '',
      commonOrgCode: ''
    }
  },
  'user-token': {
    roles: ['user'],
    permissions: [],
    userName: '普通用户',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    userInfo: {
      userId: 2,
      userCode: 'user',
      userAvatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      userName: '普通用户',
      userPhone: '',
      userEmail: '',
      orgCode: '',
      orgName: '',
      counterCode: '',
      counterName: '',
      userType: '',
      token: 'user-token',
      commonUserCode: '',
      commonOrgCode: ''
    }
  }
}

export default [
  // user login
  {
    url: '/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: '60204',
          message: 'Account and password are incorrect.'
        }
      }

      return {
        code: '000000',
        data: token
      }
    }
  },

  // get user info
  {
    url: '/user/info1',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: '50008',
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: '000000',
        message: '',
        data: info
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: config => {
      return {
        code: '000000',
        message: '',
        data: ''
      }
    }
  },

  // 用户修改登录密码
  {
    url: '/user/passwd/change',
    type: 'post',
    response: config => {
      return {
        code: '000000',
        message: '',
        data: ''
      }
    }
  },

  // 用户检查是否需要重新设定密码
  {
    url: '/user/passwd/check',
    type: 'get',
    response: config => {
      return {
        code: '000000',
        message: '',
        data: false
      }
    }
  }
]
